package com.zzyl.common.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * AI模型调用
 * @author ghy
 */
@Component
public class AiModelInvoker {

    @Autowired
    private BaiduAiProperties baiduAiProperties;

    /**
     * 调用百度千帆模型
     * @param prompt 提示词
     * @return 结果
     */
    public String qianfanInvoker(String prompt) {
        Qianfan qianfan = new Qianfan(baiduAiProperties.getAccessKey(), baiduAiProperties.getSecretKey());

        // 指定模型
        ChatResponse resp = qianfan.chatCompletion()
                .model(baiduAiProperties.getQianfanModel())
                .temperature(0.6)
                .maxOutputTokens(2048)
                .responseFormat("json_object")
                .addMessage("user", prompt)
                .execute();
        return resp.getResult();
    }
}